package apiday03.map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo3 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("语文",99);
        map.put("数学",95);
        map.put("物理",85);
        map.put("政治",88);
        map.put("英语",68);
        System.out.println(map);

        Set<String> keySet = map.keySet();
        for (String key:keySet) {
            System.out.println("key:"+key);
        }

        Collection<Integer> values = map.values();
        for (Integer value:values) {
            System.out.println("value："+value);
        }

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for (Map.Entry<String,Integer> e: entrySet) {//一个e为一组键值对
            String key = e.getKey();//获取键
            Integer value = e.getValue();//获取值
            System.out.println("key="+key+",value="+value);
        }

    }
}
